/*
package com.wds.screen.jobhandler;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.wds.api.core.util.RedisUtils;
import com.wds.screen.config.WebSocketServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

@Configuration
public class VehicleOnlineJob {

    private static AtomicInteger atomicInteger = new AtomicInteger(0);

    @Bean
    public void cacultVehicleOnline() {
        new Thread(() -> {
            while (true){
                try {
                    Thread.sleep(1000 * 60);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("查询数据:-----------");
                long currentTimeMillis = System.currentTimeMillis();
                long twoMinutesAgo = currentTimeMillis - 2 * 60 * 1000;
                //查询redis数据
                int count = RedisUtils.getClient().getScoredSortedSet("vehicle_state").count(twoMinutesAgo, true, currentTimeMillis, true);
                if (atomicInteger.get() != count){
                    atomicInteger.set(count);
                    JSONObject obj =JSONUtil.createObj();
                    obj.set("onlineCount",count);
                    try {
                        WebSocketServer.sendMessageToAllUser(obj.toString());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }).start();
    }
}
*/
